package o;

import android.content.res.Resources;
import android.os.SystemClock;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewConfiguration;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import androidx.annotation.NonNull;
import androidx.core.view.ViewCompat;
import com.huawei.appgallery.festivalanimation.particle.modifiers.SizeModifier;
import com.huawei.hms.framework.network.restclient.hwhttp.route.IPRoute;
import com.huawei.hwphy2d.physical.util.BarrierParameters;

public abstract class ir implements OnTouchListener {
    private static final int ʻॱ = ViewConfiguration.getTapTimeout();
    private int ʻ;
    private float[] ʼ = new float[]{0.0f, 0.0f};
    private Runnable ʽ;
    boolean ˊ;
    private float[] ˊॱ = new float[]{Float.MAX_VALUE, Float.MAX_VALUE};
    boolean ˋ;
    private float[] ˋॱ = new float[]{0.0f, 0.0f};
    final View ˎ;
    boolean ˏ;
    private float[] ˏॱ = new float[]{0.0f, 0.0f};
    private boolean ͺ;
    final e ॱ = new e();
    private int ॱˊ;
    private boolean ॱˋ;
    private boolean ॱˎ;
    private float[] ॱॱ = new float[]{Float.MAX_VALUE, Float.MAX_VALUE};
    private final Interpolator ᐝ = new AccelerateInterpolator();

    class a implements Runnable {
        final /* synthetic */ ir ˏ;

        a(ir irVar) {
            this.ˏ = irVar;
        }

        public void run() {
            if (this.ˏ.ˋ) {
                if (this.ˏ.ˊ) {
                    this.ˏ.ˊ = false;
                    this.ˏ.ॱ.ॱ();
                }
                e eVar = this.ˏ.ॱ;
                if (eVar.ˊ() || !this.ˏ.ˎ()) {
                    this.ˏ.ˋ = false;
                    return;
                }
                if (this.ˏ.ˏ) {
                    this.ˏ.ˏ = false;
                    this.ˏ.ˋ();
                }
                eVar.ˋ();
                this.ˏ.ˎ(eVar.ʻ(), eVar.ᐝ());
                ViewCompat.ˏ(this.ˏ.ˎ, (Runnable) this);
            }
        }
    }

    static class e {
        private int ʻ = 0;
        private long ʼ = -1;
        private int ʽ = 0;
        private float ˊ;
        private long ˋ = Long.MIN_VALUE;
        private float ˎ;
        private int ˏ;
        private int ˏॱ;
        private int ॱ;
        private long ॱॱ = 0;
        private float ᐝ;

        e() {
        }

        public void ˊ(int i) {
            this.ˏ = i;
        }

        public void ॱ(int i) {
            this.ॱ = i;
        }

        public void ॱ() {
            this.ˋ = AnimationUtils.currentAnimationTimeMillis();
            this.ʼ = -1;
            this.ॱॱ = this.ˋ;
            this.ᐝ = 0.5f;
            this.ʽ = 0;
            this.ʻ = 0;
        }

        public void ˎ() {
            long currentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
            this.ˏॱ = ir.ˊ((int) (currentAnimationTimeMillis - this.ˋ), 0, this.ॱ);
            this.ᐝ = ॱ(currentAnimationTimeMillis);
            this.ʼ = currentAnimationTimeMillis;
        }

        public boolean ˊ() {
            return this.ʼ > 0 && AnimationUtils.currentAnimationTimeMillis() > this.ʼ + ((long) this.ˏॱ);
        }

        private float ॱ(long j) {
            if (j < this.ˋ) {
                return 0.0f;
            }
            if (this.ʼ < 0 || j < this.ʼ) {
                return ir.ˏ(((float) (j - this.ˋ)) / ((float) this.ˏ), 0.0f, 1.0f) * 0.5f;
            }
            long j2 = j - this.ʼ;
            return (ir.ˏ(((float) j2) / ((float) this.ˏॱ), 0.0f, 1.0f) * this.ᐝ) + (1.0f - this.ᐝ);
        }

        private float ˎ(float f) {
            return ((-4.0f * f) * f) + (4.0f * f);
        }

        public void ˋ() {
            if (this.ॱॱ == 0) {
                throw new RuntimeException("Cannot compute scroll delta before calling start()");
            }
            long currentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
            float ˎ = ˎ(ॱ(currentAnimationTimeMillis));
            long j = currentAnimationTimeMillis - this.ॱॱ;
            this.ॱॱ = currentAnimationTimeMillis;
            this.ʽ = (int) ((((float) j) * ˎ) * this.ˎ);
            this.ʻ = (int) ((((float) j) * ˎ) * this.ˊ);
        }

        public void ˋ(float f, float f2) {
            this.ˎ = f;
            this.ˊ = f2;
        }

        public int ˏ() {
            return (int) (this.ˎ / Math.abs(this.ˎ));
        }

        public int ʼ() {
            return (int) (this.ˊ / Math.abs(this.ˊ));
        }

        public int ʻ() {
            return this.ʽ;
        }

        public int ᐝ() {
            return this.ʻ;
        }
    }

    public abstract boolean ˊ(int i);

    public abstract void ˎ(int i, int i2);

    public abstract boolean ॱॱ(int i);

    public ir(@NonNull View view) {
        this.ˎ = view;
        DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
        int i = (int) ((1575.0f * displayMetrics.density) + 0.5f);
        int i2 = (int) ((displayMetrics.density * 315.0f) + 0.5f);
        ˏ((float) i, (float) i);
        ˋ((float) i2, (float) i2);
        ˋ(1);
        ˊ(Float.MAX_VALUE, Float.MAX_VALUE);
        ˎ((float) BarrierParameters.FRICTION, (float) BarrierParameters.FRICTION);
        ॱ(1.0f, 1.0f);
        ˎ(ʻॱ);
        ॱ(IPRoute.INTERVAL);
        ˏ((int) IPRoute.INTERVAL);
    }

    public ir ˏ(boolean z) {
        if (this.ॱˋ && !z) {
            ॱ();
        }
        this.ॱˋ = z;
        return this;
    }

    @NonNull
    public ir ˏ(float f, float f2) {
        this.ˊॱ[0] = f / 1000.0f;
        this.ˊॱ[1] = f2 / 1000.0f;
        return this;
    }

    @NonNull
    public ir ˋ(float f, float f2) {
        this.ˏॱ[0] = f / 1000.0f;
        this.ˏॱ[1] = f2 / 1000.0f;
        return this;
    }

    @NonNull
    public ir ॱ(float f, float f2) {
        this.ˋॱ[0] = f / 1000.0f;
        this.ˋॱ[1] = f2 / 1000.0f;
        return this;
    }

    @NonNull
    public ir ˋ(int i) {
        this.ʻ = i;
        return this;
    }

    @NonNull
    public ir ˎ(float f, float f2) {
        this.ʼ[0] = f;
        this.ʼ[1] = f2;
        return this;
    }

    @NonNull
    public ir ˊ(float f, float f2) {
        this.ॱॱ[0] = f;
        this.ॱॱ[1] = f2;
        return this;
    }

    @NonNull
    public ir ˎ(int i) {
        this.ॱˊ = i;
        return this;
    }

    @NonNull
    public ir ॱ(int i) {
        this.ॱ.ˊ(i);
        return this;
    }

    @NonNull
    public ir ˏ(int i) {
        this.ॱ.ॱ(i);
        return this;
    }

    public boolean onTouch(View view, MotionEvent motionEvent) {
        boolean z = true;
        if (!this.ॱˋ) {
            return false;
        }
        switch (motionEvent.getActionMasked()) {
            case 0:
                this.ˏ = true;
                this.ͺ = false;
                break;
            case 1:
            case 3:
                ॱ();
                break;
            case 2:
                break;
        }
        this.ॱ.ˋ(ˊ(0, motionEvent.getX(), (float) view.getWidth(), (float) this.ˎ.getWidth()), ˊ(1, motionEvent.getY(), (float) view.getHeight(), (float) this.ˎ.getHeight()));
        if (!this.ˋ && ˎ()) {
            ˊ();
        }
        if (!(this.ॱˎ && this.ˋ)) {
            z = false;
        }
        return z;
    }

    boolean ˎ() {
        e eVar = this.ॱ;
        int ʼ = eVar.ʼ();
        int ˏ = eVar.ˏ();
        return (ʼ != 0 && ॱॱ(ʼ)) || (ˏ != 0 && ˊ(ˏ));
    }

    private void ˊ() {
        if (this.ʽ == null) {
            this.ʽ = new a(this);
        }
        this.ˋ = true;
        this.ˊ = true;
        if (this.ͺ || this.ॱˊ <= 0) {
            this.ʽ.run();
        } else {
            ViewCompat.ˏ(this.ˎ, this.ʽ, (long) this.ॱˊ);
        }
        this.ͺ = true;
    }

    private void ॱ() {
        if (this.ˊ) {
            this.ˋ = false;
        } else {
            this.ॱ.ˎ();
        }
    }

    private float ˊ(int i, float f, float f2, float f3) {
        float ˊ = ˊ(this.ʼ[i], f2, this.ॱॱ[i], f);
        if (ˊ == 0.0f) {
            return 0.0f;
        }
        float f4 = this.ˋॱ[i];
        float f5 = this.ˏॱ[i];
        float f6 = this.ˊॱ[i];
        f4 *= f3;
        if (ˊ > 0.0f) {
            return ˏ(ˊ * f4, f5, f6);
        }
        return -ˏ((-ˊ) * f4, f5, f6);
    }

    private float ˊ(float f, float f2, float f3, float f4) {
        float f5;
        float ˏ = ˏ(f * f2, 0.0f, f3);
        ˏ = ʻ(f2 - f4, ˏ) - ʻ(f4, ˏ);
        if (ˏ < 0.0f) {
            f5 = -this.ᐝ.getInterpolation(-ˏ);
        } else if (ˏ <= 0.0f) {
            return 0.0f;
        } else {
            f5 = this.ᐝ.getInterpolation(ˏ);
        }
        return ˏ(f5, SizeModifier.STABLE_STATE_SCALE, 1.0f);
    }

    private float ʻ(float f, float f2) {
        if (f2 == 0.0f) {
            return 0.0f;
        }
        switch (this.ʻ) {
            case 0:
            case 1:
                if (f >= f2) {
                    return 0.0f;
                }
                if (f >= 0.0f) {
                    return 1.0f - (f / f2);
                }
                if (this.ˋ && this.ʻ == 1) {
                    return 1.0f;
                }
                return 0.0f;
            case 2:
                if (f < 0.0f) {
                    return f / (-f2);
                }
                return 0.0f;
            default:
                return 0.0f;
        }
    }

    static int ˊ(int i, int i2, int i3) {
        if (i > i3) {
            return i3;
        }
        if (i < i2) {
            return i2;
        }
        return i;
    }

    static float ˏ(float f, float f2, float f3) {
        if (f > f3) {
            return f3;
        }
        if (f < f2) {
            return f2;
        }
        return f;
    }

    void ˋ() {
        long uptimeMillis = SystemClock.uptimeMillis();
        MotionEvent obtain = MotionEvent.obtain(uptimeMillis, uptimeMillis, 3, 0.0f, 0.0f, 0);
        this.ˎ.onTouchEvent(obtain);
        obtain.recycle();
    }
}
